package link.cocoon.common.resp;

import lombok.Data;

/**
 * @author xce
 * @date 2019/9/12 15:19
 */
@Data
public class RespData<T> implements Resp {


  private int code;
  private String message;
  private T data;


  private RespData() {
    this.code = 1;
    this.message = "失败";
  }

  private RespData(String message) {
    this.message = message;
    this.code = getSuccessCode();
  }

  public static <T> RespData<T> success() {
    return new RespData<>("成功");
  }

  public static <T> RespData<T> success(T data) {
    RespData<T> respData = success();
    respData.setData(data);
    return respData;
  }

  public static <T> RespData<T> success(String message, T data) {
    RespData<T> respData = success(data);
    respData.setMessage(message);
    return respData;
  }

  public static <T> RespData<T> error() {
    return new RespData<>();
  }


  public static <T> RespData<T> error(String message) {
    RespData<T> respData = new RespData<>();
    respData.setMessage(message);
    return respData;
  }

  public static <T> RespData<T> error(T data) {
    RespData<T> respData = error("失败");
    respData.setData(data);
    return respData;
  }

  public static <T> RespData<T> error(String message, T data) {
    RespData<T> respData = error(message);
    respData.setData(data);
    return respData;
  }

}
